﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyGun : Gun {

	private bool isFire = false;//是否攻击状态
	private float distance;//自己和敌机的距离
	


	// Use this for initialization
	void Start () {
		gatlinPool = PoolControl.instance.gatlinPool;
		cannonPool = PoolControl.instance.cannonPool;
		missilePool = PoolControl.instance.missilePool;
		laserPool = PoolControl.instance.laserPool;
		trigger = false;
	}
	
	// Update is called once per frame
	void Update () {
		
		if(target != null)
		{	
			if(weaponInfo == null)return;
			distance = Vector3.Distance(target.transform.position, transform.position);
			if(distance <= weaponInfo.AttackDistance)
			{
				// 目标不为空，攻击范围之内，
				if(!isFire)
				{
					isFire = true;
					OpenFire(weaponInfo);
				}
				else
				{

				}
			}
			else
			{
				if(isFire)
				{
					StopFire();
					isFire = false;
				}
			}
		}
		else
		{
			if(isFire)
			{
				StopFire();
				isFire = false;
			}
		}


		if(!isShow)
		{
			timer += Time.deltaTime;
		}
		else{
			timer = 0;
		}
	}


	public void SetWeapon(WeaponInfo weaponInfo)
	{
		this.weaponInfo = weaponInfo;

	}

	public WeaponInfo GetWeapon()
	{
		return base.weaponInfo;
	}

	// public void SetTarget(GameObject target)
	// {
	// 	this.target = target;
	// }


}
